<body onload="relatedProduct('<?php echo $info[id] ?>', '<?php echo $info[id_category] ?>')">
<div class="container-fluid" style="margin-top: 30px">
    <div class="row">
        <div class="col-lg-1 col-md-1 col-sm-1 col-xs-12 hidden-xs" style="text-align: center"></div> <!-- lg: >= 1200px, md:desk,lap, sm:tablet, xs:phone -->
        <div class="col-lg-10 col-md-10 col-sm-8 col-xs-12">
            <div class="row" style="padding: 20px;" id="divInfoNews">
                <div id="divAddCartReport" style="display: none" class="alert alert-success" role="alert">Đang thực hiện...</div>
                <div class="content">
                    <a href="<?php echo base_url() ?>product/view/<?php echo $info[id] ?>/title=<?php echo preg_replace('/\s+/', '+', $info[product_name]).'.html' ?>"><span style="font-weight: bold; font-size: 18px; color: green"><?php echo $info[product_name] ?></span></a>
                </div>
                <div class="content">
                    <?php $myArr = explode(",", $info[images]); if($myArr[0] == '0'){ ?>
                        <img style="width: 250px; height: 200px" src="<?php echo base_url()?>assets/images/no-image.jpg">
                    <?php }else{ ?>
                        <img style="width: 250px; height: 200px" src="<?php  echo base_url()."uploads/".$myArr[0]; ?>">
                    <?php } ?>
                </div>
                <div class="content" style="font-size: 12px;">
                    <span><i><?php echo $info[specifications] ?></i></span>
                </div>
                <div class="content" style="margin-top: 10px;">
                    <span><b>MS: </b><?php echo $info[product_code] ?></span>
                </div>
                <div class="content" style="margin-top: 10px;">
                    <span><b>Giá: </b><?php echo number_format($info[product_price1]) ?> <?php echo $info[price_unit] ?></span>
                </div>
                <div class="content">
                    <span><b>Số lượng: </b></span><input class="form-control" style="width: 10%" type="number" id="quantity" min="1" value="1">
                </div>
                <div class="content" style="margin-top: 10px;">
                    <button class="btn btn-success" onclick="shoppingCart('<?php echo $info[id] ?>', $('#quantity').val())"><span class="glyphicon glyphicon-shopping-cart"></span> Thêm vào giỏ hàng</button>
                </div>
            </div>
            <div class="row" style="border: 1px solid deepskyblue; width: 100%; padding: 10px; margin: 10px;"><?php echo htmlspecialchars_decode($info[description]) ?></div>
            <div class="row" style="margin: 10px; border-top: 1px solid #fff; padding: 5px;">
                <div class="content">
                    <span style="font-weight: bold">Sản phẩm liên quan</span>
                </div>
            </div>
            <div class="row" id="divRelatedProduct"></div>
        </div>
        <div class="col-lg-1 col-md-1 col-sm-1 col-xs-12 hidden-xs" style="text-align: center"></div>
    </div>
</div>

<!-- Modal -->
<div class="modal fade" id="modalShoppingCart" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="background-color: transparent">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title" id="myModalLabel">THÔNG TIN GIỎ HÀNG</h4>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-lg-6">
                        <div class="row">
                            <?php $myArr = explode(",", $info[images]); if($myArr[0] == '0'){ ?>
                                <img style="width: 250px; height: 200px" src="<?php echo base_url()?>assets/images/no-image.jpg">
                            <?php }else{ ?>
                                <img style="width: 250px; height: 200px" src="<?php  echo base_url()."uploads/".$myArr[0]; ?>">
                            <?php } ?>
                        </div>
                    </div>
                    <div class="col-lg-6">
                        <div class="row">
                            <a href="<?php echo base_url() ?>product/view/<?php echo $info[id] ?>/title=<?php echo preg_replace('/\s+/', '+', $info[product_name]).'.html' ?>"><span style="font-weight: bold; font-size: 18px; color: green"><?php echo $info[product_name] ?></span></a>
                        </div>
                        <div class="row">
                            <span><label id="labelModalQuantity"></label> x <?php echo number_format($info[product_price1]) ?> <?php echo $info[price_unit] ?></span>
                        </div>
                    </div>
                </div>
                <div class="row" style="padding: 10px; border-top: 1px solid #E5E5E5">
                    <div class="col-lg-6">
                        <span>Bạn có <label id="labelModalNumOfProducts"></label> sản phẩm trong giỏ hàng</span>
                    </div>
                    <div class="col-lg-6" style="text-align: right;">
                        <span><b>Tổng giá trị thanh toán <label id="labelModalTotalMoney"></label> VND</b></span>
                    </div>
                </div>
                <div class="row" style="padding: 10px; padding-left: 20px; border-top: 1px solid #E5E5E5">
                    <span><i>*Tỷ giá USD/VND hiện tại: <?php echo number_format($rate) ?></i></span>
                </div>
            </div>
            <div class="modal-footer">
<!--                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>-->
                <button type="button" class="btn btn-primary" onclick="window.location.href = '<?php echo base_url() ?>cart'">Xem giỏ hàng</button>
                <button type="button" class="btn btn-primary">Thanh toán</button>
            </div>
        </div>
    </div>
</div>

</body>

<script>
    function relatedProduct(id, id_category)
    {
        var id = id;
        var id_category = id_category;
        var url = "<?php echo base_url() ?>";
        var dataString = "id="+id+"&id_category="+id_category;
        //alert(dataString);
        $.ajax({
            type: "POST",
            url: url+"home/relatedProduct",
            data: dataString,
            success: function(x){
//                alert(x);
                $('#divRelatedProduct').html(x);
            }
        });
    }

    function shoppingCart(id, quantity)
    {
        $('#divAddCartReport').hide();
        var quantity = quantity;
//        alert(quantity);
        if(!isNumeric(quantity)){
            alert("Xin vui lòng nhập giá trị số...");
        }
        else{
            $('#divAddCartReport').show();
            var id = id;
//        alert(id);
            var url = "<?php echo base_url() ?>";
            var dataString = "id="+id+"&quantity="+quantity;
//        alert(dataString);
            $.ajax({
                type: "POST",
                url: url+"home/setNumOfProductsCart",
                data: dataString,
                success: function(x){
//                alert(x);
                    $('#spnShoppingCart').html(x);
                    $('#labelModalQuantity').html(quantity);
                    $('#labelModalNumOfProducts').html(x);

                    $.ajax({
                        url: url+"home/totalMoney/1",
                        success: function(y){
//                        alert(y);
                            $('#labelModalTotalMoney').html(y);
                            $('#divAddCartReport').hide();
                            $('#modalShoppingCart').modal('show');
                        }
                    });
                }
            });
        }
    }

    function isNumeric(input) {
        var number = /^\-{0,1}(?:[0-9]+){0,1}(?:\.[0-9]+){0,1}$/i;
        var regex = RegExp(number);
        return regex.test(input) && input.length>0;
    }
</script>
